import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from "path";

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'


// https://vitejs.dev/config/
export default defineConfig({
  base:"./",
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    })
  ],
  resolve: {
    alias: {
      "@": resolve(__dirname, "./src"),
    },
  },
  server:{
    open:true,
    proxy:{
      // 拦截 以 /api 开头的请求
      '/api': {
        // 目标服务器地址
        target: 'http://localhost:3000',
        // 如果需要代理 websockets
        ws: true,
        // 如果需要更改请求的原始主机头为目标URL的主机头
        changeOrigin: true,
        // 路径重写，移除请求URL中的 '/api' 前缀
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
      // 可以配置多个代理规则
      '/another-api': {
        target: 'http://another-backend-server.com',
        // 其他配置...
      }
    }
  }
})
